package com.lvbaoins.creditapp.task;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author : gjb
 * @description:
 * @date : 2020-12-23 10:17
 * @version: : v1.0
 */
public class ScheduledThreadPoolExecutorUtil {

    private volatile static ScheduledThreadPoolExecutorUtil instance = null;

    //操作延时
    private final int OPERATE_DELAY_TIME = 10;

    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);

    private ScheduledThreadPoolExecutorUtil() {
    }

    public static ScheduledThreadPoolExecutorUtil getInstance() {

        if (instance == null) {
            synchronized (ScheduledThreadPoolExecutorUtil.class) {
                instance = new ScheduledThreadPoolExecutorUtil();
            }
        }
        return instance;
    }

    public void execute(Runnable task) {
        scheduledExecutorService.schedule(task, OPERATE_DELAY_TIME, TimeUnit.SECONDS);
    }
}
